//
//  EditUserInfoV2ViewController.m
//  EnvironmentalProtection
//
//  Created by HCreater on 2018/11/6.
//  Copyright © 2018年 HCreater. All rights reserved.
//

#import "EditUserInfoV2ViewController.h"

#import "InputUserInfoViewController.h"
#import "OptionsPresentViewController.h"
#import "AddrChooserViewController.h"
#import "STXYChooserViewController.h"

#import <PYPhotoBrowser/PYPhotoBrowser.h>
#import <ActionSheetPicker_3_0/ActionSheetDatePicker.h>

@interface EditUserInfoV2ViewController () <PYPhotosViewDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIPickerViewDelegate, UIPickerViewDataSource>

/// 模型视图
@property (nonatomic, readonly, strong) EditUserInfoV2ViewModel* viewModel;
@property (nonatomic, readwrite, strong) NSMutableDictionary* viewDic;

// UI

//IBOutlet
@property (weak, nonatomic) IBOutlet UIView* userInfoCommonView1;
@property (weak, nonatomic) IBOutlet UIView* userInfoCommonView2;
@property (weak, nonatomic) IBOutlet UIView* zjView0;
@property (weak, nonatomic) IBOutlet UIView* zjView1;
@property (weak, nonatomic) IBOutlet UIView* zjView2;
@property (weak, nonatomic) IBOutlet UIView* qyView1;
@property (weak, nonatomic) IBOutlet UIView* jgView1;
@property (weak, nonatomic) IBOutlet UIView* qy_jgView1;
@property (weak, nonatomic) IBOutlet UIView* qy_jgView2;
@property (weak, nonatomic) IBOutlet UIView* zj_qy_jgView1;
@property (weak, nonatomic) IBOutlet UIButton* submitBtn;

@end

@implementation EditUserInfoV2ViewController
@dynamic viewModel;

- (instancetype)initWithViewModel:(SUViewModel2 *)viewModel
{
    self = [super initWithViewModel:viewModel];
    if (self)
    {
        [self initData];
        [self initLoadForRAC];
        [self initUI];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self _calViews];
}

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)initData
{
    _viewDic = [NSMutableDictionary dictionary];
}

- (void)initLoadForRAC
{
    @weakify(self)
    [[self rac_signalForSelector:@selector(viewDidLoad)] subscribeNext:^(id x)
     {
         @strongify(self)
         
     }];
}

- (void)initUI
{
    @weakify(self);
}

- (void)bindViewModel
{
    [super bindViewModel];
    
    @weakify(self)
    
    RACSignal* willAppearSignal = [self rac_signalForSelector:@selector(viewWillAppear:)];
    RACSignal* didAppearSignal = [[self rac_signalForSelector:@selector(viewDidAppear:)] replay];
    RACSignal* viewDidLayoutSVSignal = [[self rac_signalForSelector:@selector(viewDidLayoutSubviews)] replay];
    
    [[willAppearSignal replay] subscribeNext:^(id x) {
        @strongify(self)
        
        UIButton* backBtn = self.navigationItem.leftBarButtonItem.customView;
        if (backBtn)
        {
            [backBtn removeAllTargets];
            [backBtn addTarget:self action:@selector(_onBtnBack) forControlEvents:UIControlEventTouchUpInside];
        }
        
        self.view.backgroundColor = UIColorHex(#F5F5F5);
    }];
    
    [didAppearSignal subscribeNext:^(id x) {
        @strongify(self)
        
        // ScrollView 内容 未能在此时才约束
        
        //Request
    }];
    
    [[[[viewDidLayoutSVSignal take:1] zipWith:[didAppearSignal replay]] deliverOnMainThread] subscribeNext:^(id x)
     {
         @strongify(self)
         
         //重置 更新 frame
         [self _setupAllView];
     }];
    
#pragma mark -- bindViewModel
    
    UserManagerV2* um = [UserManagerV2 sharedUserManagerV2];
    
    self.viewModel.showImgPickerCmd = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input)
                                       {
                                           @strongify(self)
                                           
                                           self.viewModel.showPickerTag = [input integerValue];
                                           
                                           [self showImgPicker];
                                           
                                           return [RACSignal empty];
                                       }];
    
    [[self rac_signalForSelector:@selector(photosView:didAddImageClickedWithImages:) fromProtocol:@protocol(PYPhotosViewDelegate)] subscribeNext:^(id x)
     {
         @strongify(self)
         
         RACTuple* tuple = x;
         PYPhotoView* curPView = tuple.first;
         
         self.viewModel.ctrlTag = curPView.tag;
         
         [self.viewModel.showImgPickerCmd execute:@0];
     }];
    
    [[self rac_signalForSelector:@selector(photosView:didDeleteImageIndex:) fromProtocol:@protocol(PYPhotosViewDelegate)] subscribeNext:^(id x)
     {
         @strongify(self);
         
         [MBProgressHUD mh_showProgressHUD:@"删除中，请稍候"];
         
         RACTuple* tuple = x;
         PYPhotoView* curPView = tuple.first;
         
         self.viewModel.ctrlTag = curPView.tag;
         
         NSNumber* delImgIndexValue = tuple.second;
         
         [self.viewModel.deleteImgCmd execute:delImgIndexValue];
     }];
    [[self.viewModel.deleteImgCmd.executionSignals.switchToLatest deliverOnMainThread] subscribeNext:^(id x)
    {
        [MBProgressHUD mh_hideHUD];
        
        [MBProgressHUD mh_showTips:x];
    }];
    [[self.viewModel.deleteImgCmd.errors deliverOnMainThread] subscribeNext:^(NSError* error)
     {
         [MBProgressHUD mh_hideHUD];
         
         /// 处理验证错误的error
         if ([error.domain isEqualToString:SUCommandErrorDomain]) {
             [MBProgressHUD mh_showTips:error.userInfo[SUCommandErrorUserInfoKey]];
             return ;
         }
         [MBProgressHUD mh_showErrorTips:error];
     }];
    
    // 图片选择回调
    RACSignal* chooseImagePickerSignal = [[self rac_signalForSelector:@selector(imagePickerController:didFinishPickingMediaWithInfo:) fromProtocol:@protocol(UIImagePickerControllerDelegate)] replay];
    
    [chooseImagePickerSignal subscribeNext:^(id x) {
        @strongify(self)
        
        [MBProgressHUD mh_showProgressHUD:@"上传中，请稍候"];
        
        RACTuple* tuple = x;
        
        UIImagePickerController* picker = tuple.first;
        NSDictionary* info = tuple.second;
        
        // 从info中将图片取出，并加载到imageView当中
        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
        
        if (self.viewModel.showPickerTag == 1)
        {
            [self.viewModel.changeAvatarCmd execute:image];
        }
        else
        {
            [self.viewModel.addImgCmd execute:image];
        }
        
        [picker dismissViewControllerAnimated:YES completion:^{
            
        }];
    }];
    
    [[self.viewModel.addImgCmd.executionSignals.switchToLatest deliverOnMainThread] subscribeNext:^(id x)
     {
         [MBProgressHUD mh_hideHUD];
         
         [MBProgressHUD mh_showTips:x];
     }];
    [[self.viewModel.addImgCmd.errors deliverOnMainThread] subscribeNext:^(NSError* error)
     {
         [MBProgressHUD mh_hideHUD];
         
         /// 处理验证错误的error
         if ([error.domain isEqualToString:SUCommandErrorDomain]) {
             [MBProgressHUD mh_showTips:error.userInfo[SUCommandErrorUserInfoKey]];
             return ;
         }
         [MBProgressHUD mh_showErrorTips:error];
     }];
    
    [[self.viewModel.changeAvatarCmd.executionSignals.switchToLatest deliverOnMainThread] subscribeNext:^(id x)
     {
         [MBProgressHUD mh_hideHUD];
         
         [MBProgressHUD mh_showTips:x];
     }];
    [[self.viewModel.changeAvatarCmd.errors deliverOnMainThread] subscribeNext:^(NSError* error)
     {
         [MBProgressHUD mh_hideHUD];
         
         /// 处理验证错误的error
         if ([error.domain isEqualToString:SUCommandErrorDomain])
         {
             [MBProgressHUD mh_showTips:error.userInfo[SUCommandErrorUserInfoKey]];
             return ;
         }
         [MBProgressHUD mh_showErrorTips:error];
     }];
    
    [[self rac_signalForSelector:@selector(imagePickerControllerDidCancel:) fromProtocol:@protocol(UIImagePickerControllerDelegate)] subscribeNext:^(id x) {
        @strongify(self)
        
        RACTuple* tuple = x;
        
        UIImagePickerController* pickerC = tuple.first;
        
        [pickerC dismissViewControllerAnimated:YES completion:^{
            
        }];
    }];
    
    [[self.viewModel.normalUserReqCmd.executionSignals.switchToLatest deliverOnMainThread] subscribeNext:^(id x)
     {
         [MBProgressHUD mh_hideHUD];
     }];
    [[self.viewModel.normalUserReqCmd.errors deliverOnMainThread] subscribeNext:^(NSError* error)
     {
         [MBProgressHUD mh_hideHUD];
         
         /// 处理验证错误的error
         if ([error.domain isEqualToString:SUCommandErrorDomain]) {
             [MBProgressHUD mh_showTips:error.userInfo[SUCommandErrorUserInfoKey]];
             return ;
         }
         [MBProgressHUD mh_showErrorTips:error];
     }];
    
    [[self.viewModel.enterpriseZoneReqCmd.executionSignals.switchToLatest deliverOnMainThread] subscribeNext:^(id x)
     {
         [MBProgressHUD mh_hideHUD];
     }];
    [[self.viewModel.enterpriseZoneReqCmd.errors deliverOnMainThread] subscribeNext:^(NSError* error)
     {
         [MBProgressHUD mh_hideHUD];
         
         /// 处理验证错误的error
         if ([error.domain isEqualToString:SUCommandErrorDomain]) {
             [MBProgressHUD mh_showTips:error.userInfo[SUCommandErrorUserInfoKey]];
             return ;
         }
         [MBProgressHUD mh_showErrorTips:error];
     }];
    
    [[self.viewModel.institutionZoneReqCmd.executionSignals.switchToLatest deliverOnMainThread] subscribeNext:^(id x)
     {
         [MBProgressHUD mh_hideHUD];
     }];
    [[self.viewModel.institutionZoneReqCmd.errors deliverOnMainThread] subscribeNext:^(NSError* error)
     {
         [MBProgressHUD mh_hideHUD];
         
         /// 处理验证错误的error
         if ([error.domain isEqualToString:SUCommandErrorDomain]) {
             [MBProgressHUD mh_showTips:error.userInfo[SUCommandErrorUserInfoKey]];
             return ;
         }
         [MBProgressHUD mh_showErrorTips:error];
     }];
    
    [[self.submitBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x)
    {
        [MBProgressHUD mh_showProgressHUD:@"提交中..."];
        
        [self.viewModel.submitCmd execute:nil];
    }];
    [[self.viewModel.submitCmd.executionSignals.switchToLatest deliverOnMainThread] subscribeNext:^(id x)
    {
        if (x && [x isKindOfClass:[NSString class]])
        {
            [MBProgressHUD mh_hideHUD];
            
            [MBProgressHUD mh_showTips:x];
            
            [[UserManagerV2 sharedUserManagerV2] updateUserInfo];
            
            [self.navigationController popViewControllerAnimated:YES];
        }
    }];
    [[self.viewModel.submitCmd.errors deliverOnMainThread] subscribeNext:^(NSError* error)
    {
        [MBProgressHUD mh_hideHUD];
        
        /// 处理验证错误的error
        if ([error.domain isEqualToString:SUCommandErrorDomain]) {
            [MBProgressHUD mh_showTips:error.userInfo[SUCommandErrorUserInfoKey]];
            return ;
        }
        [MBProgressHUD mh_showErrorTips:error];
    }];
}

#pragma mark - 更新初始化 操作
- (void)_calViews
{
    [self _rebuildViewDic];
    
    //隐藏所有
    NSArray* views = @[self.userInfoCommonView1, self.userInfoCommonView2, self.zjView0, self.zjView1, self.zjView2, self.qyView1, self.jgView1, self.qy_jgView1, self.qy_jgView2, self.zj_qy_jgView1];
    NSMutableArray* viewShowValues = [NSMutableArray arrayWithArray:@[@NO, @NO, @NO, @NO, @NO, @NO, @NO, @NO, @NO, @NO]];
    
    switch (self.viewModel.type)
    {
        case 0: //个人
        {
            [viewShowValues replaceObjectAtIndex:0 withObject:@YES];
            [viewShowValues replaceObjectAtIndex:1 withObject:@YES];
        }
            break;
            
        case 1: //专家
        {
            [viewShowValues replaceObjectAtIndex:0 withObject:@YES];
            [viewShowValues replaceObjectAtIndex:1 withObject:@YES];
            [viewShowValues replaceObjectAtIndex:2 withObject:@YES];
            [viewShowValues replaceObjectAtIndex:3 withObject:@YES];
            [viewShowValues replaceObjectAtIndex:4 withObject:@YES];
            [viewShowValues replaceObjectAtIndex:9 withObject:@YES];
        }
            break;
            
        case 2: //企业
        {
            [viewShowValues replaceObjectAtIndex:0 withObject:@YES];
            [viewShowValues replaceObjectAtIndex:5 withObject:@YES];
            [viewShowValues replaceObjectAtIndex:7 withObject:@YES];
            [viewShowValues replaceObjectAtIndex:8 withObject:@YES];
            [viewShowValues replaceObjectAtIndex:9 withObject:@YES];
        }
            break;
            
        case 3: //机构
        {
            [viewShowValues replaceObjectAtIndex:0 withObject:@YES];
            [viewShowValues replaceObjectAtIndex:6 withObject:@YES];
            [viewShowValues replaceObjectAtIndex:7 withObject:@YES];
            [viewShowValues replaceObjectAtIndex:8 withObject:@YES];
            [viewShowValues replaceObjectAtIndex:9 withObject:@YES];
        }
            break;
            
        default:
            break;
    }
    
    for (NSInteger index=0; index<viewShowValues.count; index++)
    {
        NSNumber* value = viewShowValues[index];
        
        UIView* curView = views[index];
        
        [self _showHideView:curView isShow:[value boolValue]];
    }
}

- (void)_setupAllView
{
    @weakify(self);
    
    UserManagerV2* um = [UserManagerV2 sharedUserManagerV2];
    
    //通用 用户信息部分 userInfoCommonView1
    UIView* avatarView = [self.userInfoCommonView1 viewWithTag:100];
    {
        UIImageView* avatarImgView = [avatarView viewWithTag:1000];
        UIButton* avatarBtn = [avatarView viewWithTag:1001];
        {
            avatarImgView.layer.cornerRadius = avatarImgView.frame.size.height/2.0f;
            avatarImgView.layer.masksToBounds = YES;
            
            [[RACObserve(um.userData, headimg) distinctUntilChanged] subscribeNext:^(id x)
            {
                [avatarImgView yy_setImageWithURL:[NSURL URLWithString:x] placeholder:MHImageNamed(@"placeholderLogo")];
            }];
            
            [[avatarBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
                
                @strongify(self);
                [self _try2ChangeAvatar];
            }];
        }
        
        UIView* nicknameView = [self.userInfoCommonView1 viewWithTag:101];
        UILabel* nicknameLabel = [nicknameView viewWithTag:1010];
        UIButton* nicknameBtn = [nicknameView viewWithTag:1011];
        {
            RAC(nicknameLabel, text) = [[RACObserve(self.viewModel, nickname) distinctUntilChanged] map:^id(id value)
            {
                NSString* nickname = value;
                
                return [nickname isNotBlank] ? nickname : @"未完善";
            }];
            
            [[nicknameBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
                @strongify(self);
                [self _push2EditNickNameVC];
            }];
        }
        
        UIView* syView = [self.userInfoCommonView1 viewWithTag:102];
        UILabel* syLabel = [syView viewWithTag:1020];
        UIButton* syBtn = [syView viewWithTag:1021];
        {
            RACSignal* syTextChangeSignal = [RACObserve(self.viewModel, sy) distinctUntilChanged];
            
            RAC(syLabel, text) = [[syTextChangeSignal replay] map:^id(id value)
            {
                NSString* sy = value;
                
                return [sy isNotBlank] ? sy : @"未完善";
            }];
            RAC(syLabel, textColor) = [[syTextChangeSignal replay] map:^id(id value)
                                       {
                                           NSString* sy = value;
                                           
                                           return [sy isEqualToString:@"未完善"] ? UIColorHex(#008f58) : UIColorHex(#424242);
                                       }];
            
            [[syBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
                @strongify(self);
                [self _push2EditSYVC];
            }];
        }
    }
    
    // userInfoCommonView2
    if (self.viewModel.type == 0 || self.viewModel.type == 1)
    {
        UIView* sexView = [self.userInfoCommonView2 viewWithTag:130];
        UILabel* sexLabel = [sexView viewWithTag:1300];
        UIButton* sexBtn = [sexView viewWithTag:1301];
        {
            RACSignal* sexTextChangeSignal = [RACObserve(self.viewModel, sex) distinctUntilChanged];
            
            RAC(sexLabel, text) = [sexTextChangeSignal replay];
            RAC(sexLabel, textColor) = [[sexTextChangeSignal replay] map:^id(id value)
            {
                NSString* strSex = value;
                
                return [strSex isEqualToString:@"未知"] ? UIColorHex(#008f58) : UIColorHex(#424242);
            }];
            
            [[sexBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
                @strongify(self);
                [self _chooseSex];
            }];
        }
        
        UIView* bdView = [self.userInfoCommonView2 viewWithTag:131];
        UILabel* bdLabel = [bdView viewWithTag:1310];
        UIButton* bdBtn = [bdView viewWithTag:1311];
        {
            RACSignal* bdTextChangeSignal = [RACObserve(self.viewModel, birth) distinctUntilChanged];
            RAC(bdLabel, text) = [bdTextChangeSignal replay];
            RAC(bdLabel, textColor) = [[bdTextChangeSignal replay] map:^id(id value)
                                        {
                                            NSString* strValue = value;
                                            
                                            return [strValue isEqualToString:@"未完善"] ? UIColorHex(#008f58) : UIColorHex(#424242);
                                        }];
            
            [[bdBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
                @strongify(self);
                [self _chooseDate];
            }];
        }
        
        UIView* zoneView = [self.userInfoCommonView2 viewWithTag:132];
        UILabel* zoneLabel = [zoneView viewWithTag:1320];
        UIButton* zoneBtn = [zoneView viewWithTag:1321];
        {
            RACSignal* zoneTextChangeSignal = [RACObserve(self.viewModel, zone) distinctUntilChanged];
            RAC(zoneLabel, text) = [zoneTextChangeSignal replay];
            RAC(zoneLabel, textColor) = [[zoneTextChangeSignal replay] map:^id(id value)
                                       {
                                           NSString* strValue = value;
                                           
                                           return [strValue isEqualToString:@"未完善"] ? UIColorHex(#008f58) : UIColorHex(#424242);
                                       }];
            
            [[zoneBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
                @strongify(self);
                [self _chooseZone];
            }];
        }
    }
    
    // 专家View
    if (self.viewModel.type == 1)
    {
        UIView* nameView = [self.zjView0 viewWithTag:190];
        UILabel* nameLabel = [nameView viewWithTag:1900];
        UIButton* nameBtn = [nameView viewWithTag:1901];
        {
            RACSignal* nameTextChangeSignal = [RACObserve(self.viewModel, expertContacter) distinctUntilChanged];
            RAC(nameLabel, text) = [nameTextChangeSignal replay];
            RAC(nameLabel, textColor) = [[nameTextChangeSignal replay] map:^id(id value)
                                         {
                                             NSString* strValue = value;
                                             
                                             return [strValue isEqualToString:@"未完善"] ? UIColorHex(#008f58) : UIColorHex(#424242);
                                         }];
            
//            [[nameBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
//                @strongify(self);
//                [self _chooseZone];
//            }];
        }
        
        UIView* mobileView = [self.zjView0 viewWithTag:191];
        UILabel* mobileLabel = [mobileView viewWithTag:1910];
        UIButton* mobileBtn = [mobileView viewWithTag:1911];
        {
            RACSignal* mobileTextChangeSignal = [RACObserve(self.viewModel, expertContactMobile) distinctUntilChanged];
            RAC(mobileLabel, text) = [mobileTextChangeSignal replay];
            RAC(mobileLabel, textColor) = [[mobileTextChangeSignal replay] map:^id(id value)
                                         {
                                             NSString* strValue = value;
                                             
                                             return [strValue isEqualToString:@"未完善"] ? UIColorHex(#008f58) : UIColorHex(#424242);
                                         }];
            
//            [[nameBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
//                @strongify(self);
//                [self _chooseZone];
//            }];
        }
        
        UIView* zjView = [self.zjView1 viewWithTag:110];
        UILabel* jjLabel = [zjView viewWithTag:1100];
        UIButton* jjBtn = [zjView viewWithTag:1101];
        {
            RACSignal* introTextChangeSignal = [RACObserve(self.viewModel, intro) distinctUntilChanged];
            RAC(jjLabel, text) = [introTextChangeSignal replay];
            RAC(jjLabel, textColor) = [[introTextChangeSignal replay] map:^id(id value)
                                         {
                                             NSString* strValue = value;
                                             
                                             return [strValue isEqualToString:@"未完善"] ? UIColorHex(#008f58) : UIColorHex(#424242);
                                         }];
            
            [[jjBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
                @strongify(self);
                [self _push2EditIntroVC];
            }];
        }
        
        // 个人证书
        UIView* personCertView = [self.zjView2 viewWithTag:170];
        // 图片添加器
        [personCertView removeAllSubviews];
        {
            NSInteger imgColNum = 3;
            
            // 计算大小
            CGFloat imgOffset = 16;
            CGFloat imgSize = (personCertView.frame.size.width - ((imgColNum + 1)*imgOffset)) / imgColNum;
            
            NSMutableArray* imgs = [NSMutableArray array];
            PYPhotosView *photosView = [PYPhotosView photosViewWithImages:imgs];
            photosView.photosState = PYPhotosViewStateDidCompose;
            photosView.photosMaxCol = 3;
            photosView.autoLayoutWithWeChatSytle = YES;
            photosView.autoSetPhotoState = NO;
            photosView.oneImageFullFrame = NO;
            photosView.photoWidth = imgSize;
            photosView.photoHeight = imgSize;
            photosView.photoMargin = imgOffset;
            photosView.delegate = self;
            
            NSInteger row = 1;
            photosView.frame = (CGRect) {0, 0, personCertView.frame.size.width, imgSize*row + imgOffset*(row - 1)};
            photosView.tag = 10;
            [personCertView addSubview:photosView];
            //修改约束
            for (NSLayoutConstraint* curConstraint in self.zjView2.constraints)
            {
                if (curConstraint.firstAttribute == NSLayoutAttributeHeight)
                {
                    curConstraint.constant = photosView.frame.size.height + 8.0f*2.0f + 44.0f;
                    
                    break;
                }
            }
        }
    }
    
    // 企业 qyView1
    if (self.viewModel.type == 2)
    {
        UIView* introView = [self.qyView1 viewWithTag:120];
        UILabel* introLabel = [introView viewWithTag:1200];
        UIButton* introBtn = [introView viewWithTag:1201];
        {
            RACSignal* companyIntroTextChangeSignal = [RACObserve(self.viewModel, companyIntro) distinctUntilChanged];
            RAC(introLabel, text) = [companyIntroTextChangeSignal replay];
            RAC(introLabel, textColor) = [[companyIntroTextChangeSignal replay] map:^id(id value)
                                       {
                                           NSString* strValue = value;
                                           
                                           return [strValue isEqualToString:@"未完善"] ? UIColorHex(#008f58) : UIColorHex(#424242);
                                       }];
            
            [[introBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
                @strongify(self);
                [self _push2EditCompanyIntroVC];
            }];
        }
        
        UIView* contactView = [self.qyView1 viewWithTag:121];
        UILabel* contactLabel = [contactView viewWithTag:1210];
        UIButton* contactBtn = [contactView viewWithTag:1211];
        {
            RACSignal* companyContactTextChangeSignal = [RACObserve(self.viewModel, companyContact) distinctUntilChanged];
            RAC(contactLabel, text) = [companyContactTextChangeSignal replay];
            RAC(contactLabel, textColor) = [[companyContactTextChangeSignal replay] map:^id(id value)
                                          {
                                              NSString* strValue = value;
                                              
                                              return [strValue isEqualToString:@"未完善"] ? UIColorHex(#008f58) : UIColorHex(#424242);
                                          }];
            
            [[contactBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
                @strongify(self);
                [self _push2EditCompanyInfo2VC];
            }];
        }
    }
    
    // 机构 jgView1
    if (self.viewModel.type == 3)
    {
        UIView* introView = [self.jgView1 viewWithTag:150];
        UILabel* introLabel = [introView viewWithTag:1500];
        UIButton* introBtn = [introView viewWithTag:1501];
        {
            RACSignal* mechanismIntroTextChangeSignal = [RACObserve(self.viewModel, mechanismIntro) distinctUntilChanged];
            RAC(introLabel, text) = [mechanismIntroTextChangeSignal replay];
            RAC(introLabel, textColor) = [[mechanismIntroTextChangeSignal replay] map:^id(id value)
                                            {
                                                NSString* strValue = value;
                                                
                                                return [strValue isEqualToString:@"未完善"] ? UIColorHex(#008f58) : UIColorHex(#424242);
                                            }];
            
            [[introBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
                @strongify(self);
                [self _push2EditMechanismIntroVC];
            }];
        }
        
        UIView* contactView = [self.jgView1 viewWithTag:151];
        UILabel* contactLabel = [contactView viewWithTag:1510];
        UIButton* contactBtn = [contactView viewWithTag:1511];
        {
            RACSignal* mechanismContactTextChangeSignal = [RACObserve(self.viewModel, mechanismContact) distinctUntilChanged];
            RAC(contactLabel, text) = [mechanismContactTextChangeSignal replay];
            RAC(contactLabel, textColor) = [[mechanismContactTextChangeSignal replay] map:^id(id value)
                                          {
                                              NSString* strValue = value;
                                              
                                              return [strValue isEqualToString:@"未完善"] ? UIColorHex(#008f58) : UIColorHex(#424242);
                                          }];
            
            [[contactBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
                @strongify(self);
                [self _push2EditCompanyInfo1VC];
            }];
        }
        
        UIView* serContentView = [self.jgView1 viewWithTag:152];
        UILabel* serContentLabel = [serContentView viewWithTag:1520];
        UIButton* serContentBtn = [serContentView viewWithTag:1521];
        {
            RACSignal* serContentTextChangeSignal = [RACObserve(self.viewModel, mechanismServContent) distinctUntilChanged];
            RAC(serContentLabel, text) = [serContentTextChangeSignal replay];
            RAC(serContentLabel, textColor) = [[serContentTextChangeSignal replay] map:^id(id value)
                                            {
                                                NSString* strValue = value;
                                                
                                                return [strValue isEqualToString:@"未完善"] ? UIColorHex(#008f58) : UIColorHex(#424242);
                                            }];
            
            [[serContentBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
                @strongify(self);
                [self _push2EditMechanismServVC];
            }];
        }
    }
    
    // 机构 企业 qy_jgView1
    if (self.viewModel.type == 2 || self.viewModel.type == 3)
    {
        UIView* zoneView = [self.qy_jgView1 viewWithTag:140];
        UILabel* zoneLabel = [zoneView viewWithTag:1400];
        UIButton* zoneBtn = [zoneView viewWithTag:1401];
        {
            RACSignal* zoneTextChangeSignal = [RACObserve(self.viewModel, mczone) distinctUntilChanged];
            RAC(zoneLabel, text) = [zoneTextChangeSignal replay];
            RAC(zoneLabel, textColor) = [[zoneTextChangeSignal replay] map:^id(id value)
                                               {
                                                   NSString* strValue = value;
                                                   
                                                   return [strValue isEqualToString:@"未完善"] ? UIColorHex(#008f58) : UIColorHex(#424242);
                                               }];
            
            [[zoneBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
                @strongify(self);
                [self _chooseZone];
            }];
        }
        
        // 营业证书
        UIView* busyCertView = [self.qy_jgView2 viewWithTag:160];
        // 图片添加器
        [busyCertView removeAllSubviews];
        {
            NSInteger imgColNum = 3;
            
            // 计算大小
            CGFloat imgOffset = 16;
            CGFloat imgSize = (busyCertView.frame.size.width - ((imgColNum + 1)*imgOffset)) / imgColNum;
            
            NSMutableArray* imgs = [NSMutableArray array];
            PYPhotosView *photosView = [PYPhotosView photosViewWithImages:imgs];
            photosView.photosState = PYPhotosViewStateDidCompose;
            photosView.photosMaxCol = 3;
            photosView.imagesMaxCountWhenWillCompose = 9;
            photosView.autoLayoutWithWeChatSytle = NO;
            photosView.oneImageFullFrame = NO;
            photosView.photoWidth = imgSize;
            photosView.photoHeight = imgSize;
            photosView.photoMargin = imgOffset;
            photosView.delegate = self;
            
            NSInteger row = 1;
            photosView.frame = (CGRect) {0, 0, busyCertView.frame.size.width, imgSize*row + imgOffset*(row - 1)};
            photosView.tag = 11;
            [busyCertView addSubview:photosView];
            //修改约束
            for (NSLayoutConstraint* curConstraint in self.qy_jgView2.constraints)
            {
                if (curConstraint.firstAttribute == NSLayoutAttributeHeight)
                {
                    curConstraint.constant = photosView.frame.size.height + 8.0f*2.0f + 44.0f;
                    
                    break;
                }
            }
        }
    }
    
    // 专家 机构 企业
    if (self.viewModel.type == 1 || self.viewModel.type == 2 || self.viewModel.type == 3)
    {
        // 相关证书
        UIView* aboutCertView = [self.zj_qy_jgView1 viewWithTag:180];
        // 图片添加器
        [aboutCertView removeAllSubviews];
        {
            NSInteger imgColNum = 3;
            
            // 计算大小
            CGFloat imgOffset = 16;
            CGFloat imgSize = (aboutCertView.frame.size.width - ((imgColNum + 1)*imgOffset)) / imgColNum;
            
            NSMutableArray* imgs = [NSMutableArray array];
            PYPhotosView *photosView = [PYPhotosView photosViewWithImages:imgs];
            photosView.photosState = PYPhotosViewStateDidCompose;
            photosView.photosMaxCol = 3;
            photosView.imagesMaxCountWhenWillCompose = 9;
            photosView.autoLayoutWithWeChatSytle = NO;
            photosView.oneImageFullFrame = NO;
            photosView.photoWidth = imgSize;
            photosView.photoHeight = imgSize;
            photosView.photoMargin = imgOffset;
            photosView.delegate = self;
            
            NSInteger row = 1;
            photosView.frame = (CGRect) {0, 0, aboutCertView.frame.size.width, imgSize*row + imgOffset*(row - 1)};
            photosView.tag = 12;
            [aboutCertView addSubview:photosView];
            //修改约束
            for (NSLayoutConstraint* curConstraint in self.zj_qy_jgView1.constraints)
            {
                if (curConstraint.firstAttribute == NSLayoutAttributeHeight)
                {
                    curConstraint.constant = photosView.frame.size.height + 8.0f*2.0f + 44.0f;
                    
                    break;
                }
            }
        }
    }
    
// 绑定 PYPhotoView的更新信号
    // 个人身份证
    if (self.viewModel.type == 1)
    {
        UIView* personCertView = [self.zjView2 viewWithTag:170];
        
        [self.viewModel.personCertImagesChangeSignal subscribeNext:^(id x)
         {
             @strongify(self);
             
             PYPhotosView* photosView = [personCertView viewWithTag:10];
             if (photosView != nil)
             {
                 photosView.originalUrls = x;
             }
             
             NSInteger imgCount = [x count] + 1;
             imgCount = imgCount>9?9:imgCount;
             NSInteger imgColNum = 3;
             CGFloat imgOffset = 16;
             CGFloat imgSize = (personCertView.frame.size.width - ((imgColNum + 1)*imgOffset)) / imgColNum;
             
             NSInteger row = imgCount/3 + (imgCount%3>0?1:0);
             CGFloat viewHeight = imgSize*row + imgOffset*(row - 1);
             //修改约束
             for (NSLayoutConstraint* curConstraint in self.zjView2.constraints)
             {
                 if (curConstraint.firstAttribute == NSLayoutAttributeHeight)
                 {
                     curConstraint.constant = viewHeight + 8.0f*2.0f + 44.0f;
                     break;
                 }
             }
         }];
    }
    
    if (self.viewModel.type == 1 || self.viewModel.type == 2 || self.viewModel.type == 3)
    {
        UIView* aboutCertView = [self.zj_qy_jgView1 viewWithTag:180];
        
        [self.viewModel.aboutCertImagesChangeSignal subscribeNext:^(id x)
         {
             @strongify(self);
             
             PYPhotosView* photosView = [aboutCertView viewWithTag:12];
             if (photosView != nil)
             {
                 photosView.originalUrls = x;
             }
             
             NSInteger imgCount = [x count] + 1;
             imgCount = imgCount>9?9:imgCount;
             NSInteger imgColNum = 3;
             CGFloat imgOffset = 16;
             CGFloat imgSize = (aboutCertView.frame.size.width - ((imgColNum + 1)*imgOffset)) / imgColNum;
             
             NSInteger row = imgCount/3 + (imgCount%3>0?1:0);
             CGFloat viewHeight = imgSize*row + imgOffset*(row - 1);
             //修改约束
             for (NSLayoutConstraint* curConstraint in self.zj_qy_jgView1.constraints)
             {
                 if (curConstraint.firstAttribute == NSLayoutAttributeHeight)
                 {
                     curConstraint.constant = viewHeight + 8.0f*2.0f + 44.0f;
                     break;
                 }
             }
         }];
    }
    
    if (self.viewModel.type == 2 || self.viewModel.type == 3)
    {
        UIView* busyCertView = [self.qy_jgView2 viewWithTag:160];
        
        [self.viewModel.busyCertImagesChangeSignal subscribeNext:^(id x)
         {
             @strongify(self);
             
             PYPhotosView* photosView = [busyCertView viewWithTag:11];
             if (photosView != nil)
             {
                 photosView.originalUrls = x;
             }
             
             NSInteger imgCount = [x count] + 1;
             imgCount = imgCount>9?9:imgCount;
             NSInteger imgColNum = 3;
             CGFloat imgOffset = 16;
             CGFloat imgSize = (busyCertView.frame.size.width - ((imgColNum + 1)*imgOffset)) / imgColNum;
             
             NSInteger row = imgCount/3 + (imgCount%3>0?1:0);
             CGFloat viewHeight = imgSize*row + imgOffset*(row - 1);
             //修改约束
             for (NSLayoutConstraint* curConstraint in self.qy_jgView2.constraints)
             {
                 if (curConstraint.firstAttribute == NSLayoutAttributeHeight)
                 {
                     curConstraint.constant = viewHeight + 8.0f*2.0f + 44.0f;
                     break;
                 }
             }
         }];
    }
}

#pragma mark - Delegate 一些无法用RAC实现
// UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
}

#pragma mark-代理方法
// 设立实现代理，注意要返回UIModalPresentationNone
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
{
    return UIModalPresentationNone;
}

#pragma mark - 功能
- (void)_onBtnBack
{
    @weakify(self);
    
    UserManagerV2* um = [UserManagerV2 sharedUserManagerV2];
    
    [MBProgressHUD mh_showProgressHUD:@""];
    
    [[um rac_signalForSelector:@selector(userDataRefresh)] subscribeNext:^(id x)
    {
        @strongify(self);
        
        [MBProgressHUD mh_hideHUD];
        
        //返回
        [self.navigationController popViewControllerAnimated:YES];
    }];
    
    [um updateUserInfo];
}

- (void)_rebuildViewDic
{
    [_viewDic setObject:@(self.userInfoCommonView1.frame.size.height) forKey:@(self.userInfoCommonView1.tag)];
    [_viewDic setObject:@(self.userInfoCommonView2.frame.size.height) forKey:@(self.userInfoCommonView2.tag)];
    [_viewDic setObject:@(self.zjView1.frame.size.height) forKey:@(self.zjView1.tag)];
    [_viewDic setObject:@(self.zjView2.frame.size.height) forKey:@(self.zjView2.tag)];
    [_viewDic setObject:@(self.qyView1.frame.size.height) forKey:@(self.qyView1.tag)];
    [_viewDic setObject:@(self.jgView1.frame.size.height) forKey:@(self.jgView1.tag)];
    [_viewDic setObject:@(self.qy_jgView1.frame.size.height) forKey:@(self.qy_jgView1.tag)];
    [_viewDic setObject:@(self.qy_jgView2.frame.size.height) forKey:@(self.qy_jgView2.tag)];
    [_viewDic setObject:@(self.zj_qy_jgView1.frame.size.height) forKey:@(self.zj_qy_jgView1.tag)];
}

- (void)_showHideView:(UIView*)view isShow:(BOOL)isShow
{
    CGFloat height = [_viewDic[@(view.tag)] floatValue];
    
    for (NSLayoutConstraint* curConstraint in view.constraints)
    {
        if (curConstraint.firstAttribute == NSLayoutAttributeHeight)
        {
            curConstraint.constant = isShow?height:0;
            
            break;
        }
    }
}

- (void)_try2ChangeAvatar
{
    [self.viewModel.showImgPickerCmd execute:@1];
}

- (void)showImgPicker
{
    // 创建UIImagePickerController实例
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    // 设置代理
    imagePickerController.delegate = self;
    // 是否允许编辑（默认为NO）
    imagePickerController.allowsEditing = YES;
    
    // 创建一个警告控制器
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"选取图片" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    // 设置警告响应事件
    UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        // 设置照片来源为相机
        imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        
        // 设置进入相机时使用前置或后置摄像头
        imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
        
        // 展示选取照片控制器
        [self presentViewController:imagePickerController animated:YES completion:^{}];
    }];
    
    UIAlertAction *photosAction = [UIAlertAction actionWithTitle:@"从相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:imagePickerController animated:YES completion:^{}];
    }];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    
    // 判断是否支持相机
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        // 添加警告按钮
        [alert addAction:cameraAction];
    }
    
    [alert addAction:photosAction];
    [alert addAction:cancelAction];
    
    alert.popoverPresentationController.sourceView = self.view;
    alert.popoverPresentationController.sourceRect = CGRectMake(0,0,1.0,1.0);
    
    // 展示警告控制器
    [self presentViewController:alert animated:YES completion:nil];
}

- (void)_chooseSex
{
    OptionsPresentViewController* vc = nil;
    
    @weakify(self);
    // 测试更多弹出
    OptionsPresentViewModel* vm = [[OptionsPresentViewModel alloc] initWithParams:@{}];
    vm.titles = @[@"男", @"女"];
    vm.topTitle = @"选择性别";
    vm.selectCmd = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input)
                    {
                        @strongify(self);
                        
                        NSIndexPath* indexPath = input;
                        
                        NSLog(@"选择性别 : %@", indexPath.row == 0 ? @"男" : @"女");
                        
                        NSString* sex = indexPath.row == 0 ? @"男" : @"女";
                        self.viewModel.personSubmitData.sex = sex;
                        
                        [self.viewModel.normalUserReqCmd execute:nil];
                        [MBProgressHUD mh_showProgressHUD:@""];
                        
                        [[UIViewController getCurrentVC] dismissViewControllerAnimated:vc completion:^{
                            
                        }];
                        
                        return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
                            
                            [subscriber sendCompleted];
                            
                            return nil;
                        }];
                    }];
    vc = [[OptionsPresentViewController alloc] initWithViewModel:vm];
    vc.view.backgroundColor = [UIColor clearColor];
    //         vc.modalPresentationStyle = UIModalPresentationOverCurrentContext|UIModalPresentationFullScreen;
    if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) {
        vc.modalPresentationStyle=UIModalPresentationOverCurrentContext;
    }else{
        vc.modalPresentationStyle=UIModalPresentationCurrentContext;
    }
    [[UIViewController getCurrentVC] presentViewController:vc animated:YES completion:^
     {
         vc.view.backgroundColor = UIColorHex(#0000000f);
     }];
}

- (void)_chooseDate
{
    @weakify(self)
    ActionSheetDatePicker* picker = [[ActionSheetDatePicker alloc] initWithTitle:@"选择日期"
                                                                  datePickerMode:UIDatePickerModeDate
                                                                    selectedDate:[NSDate date]
                                                                       doneBlock:^(ActionSheetDatePicker *picker, id selectedDate, id origin) {
                                                                           @strongify(self)
                                                                           
                                                                           NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
                                                                           [dateFormatter setDateFormat:@"yyyy-MM-dd"];
                                                                           NSString* resultString = [dateFormatter stringFromDate:selectedDate];
                                                                           
                                                                           NSLog(@"选择日期 ： %@", resultString);
                                                                           
//                                                                           self.viewModel.buildDate = selectedDate;
                                                                           
                                                                           self.viewModel.personSubmitData.birth = resultString;
                                                                           
                                                                           [self.viewModel.normalUserReqCmd execute:nil];
                                                                           [MBProgressHUD mh_showProgressHUD:@""];
                                                                       }
                                                                     cancelBlock:^(ActionSheetDatePicker *picker) {
                                                                         NSLog(@"cancel");
                                                                         
                                                                     }
                                                                          origin:self.view];
    [picker setMinimumDate:[NSDate dateWithTimeIntervalSinceNow:-(50 * 365 * 24 * 3600)]];
    [picker setMaximumDate:[NSDate date]];
    
    UIButton* doneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    doneBtn.frame = (CGRect) {0, 0, 64, 44};
    [doneBtn setTitleColor:UIColorHex(#00A815) forState:UIControlStateNormal];
    [doneBtn setTitle:@"完成" forState:UIControlStateNormal];
    [picker setDoneButton:[[UIBarButtonItem alloc] initWithCustomView:doneBtn]];
    
    UIButton* cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame = (CGRect) {0, 0, 64, 44};
    [cancelBtn setTitleColor:UIColorHex(#00A815) forState:UIControlStateNormal];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [picker setCancelButton:[[UIBarButtonItem alloc] initWithCustomView:cancelBtn]];
    
    picker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
    
    [picker showActionSheetPicker];
}

- (void)_chooseZone
{
    DataManager* dm = [DataManager sharedDataManager];
    
    @weakify(self)
    AddrChooserViewModel* vm = [[AddrChooserViewModel alloc] initWithParams:@{SUViewModelTitleKey:@"选择地区"}];
    vm.isShowCountryChoose = NO;
    vm.chooseBlock = ^(ProvinceListData* choosePData)
    {
        @strongify(self)
        
        if (self.viewModel.type == 2)
        {
            self.viewModel.enterpriseSubmitData.zoneData = choosePData;
            
            [self.viewModel.enterpriseZoneReqCmd execute:nil];
            [MBProgressHUD mh_showProgressHUD:@""];
        }
        else if (self.viewModel.type == 3)
        {
            self.viewModel.insutitutionSumitData.zoneData = choosePData;
            
            [self.viewModel.institutionZoneReqCmd execute:nil];
            [MBProgressHUD mh_showProgressHUD:@""];
        }
        else
        {
            self.viewModel.personSubmitData.zone = choosePData.areaID;
            
            [self.viewModel.normalUserReqCmd execute:nil];
            [MBProgressHUD mh_showProgressHUD:@""];
        }
        
        //        self.viewModel.chooseProvinceData = choosePData;
    };
    AddrChooserViewController* vc = [[AddrChooserViewController alloc] initWithViewModel:vm];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 跳转
- (void)_push2EditNickNameVC
{
    @weakify(self);
    
    InputUserInfoViewModel* vm = [[InputUserInfoViewModel alloc] initWithParams:@{SUViewModelTitleKey:@"修改昵称"}];
    vm.type = 0;
    vm.reqType = @"USER_NICKNAME";
    InputUserInfoViewController* vc = [[InputUserInfoViewController alloc] initWithViewModel:vm];
    
    [[[RACObserve(vm, strTF) deliverOnMainThread] filter:^BOOL(id value) {
        return value != nil;
    }] subscribeNext:^(id x)
     {
         NSLog(@"TF is %@", x);
         
         @strongify(self);
         
         self.viewModel.personSubmitData.nickname = x;
     }];
    
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)_push2EditSYVC
{
    @weakify(self);
    
    STXYChooserViewModel* vm = [[STXYChooserViewModel alloc] initWithParams:@{SUViewModelTitleKey:@"修改生态宣言"}];
    vm.strText = self.viewModel.personSubmitData.sy;
    vm.chooseBlock = ^(NSString* text)
    {
        @strongify(self);

        [self.viewModel chooseSTXY:text];
        
        [self.viewModel.normalUserReqCmd execute:nil];
        [MBProgressHUD mh_showProgressHUD:@""];
    };
    STXYChooserViewController* vc = [[STXYChooserViewController alloc] initWithViewModel:vm];
    
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)_push2EditIntroVC
{
    @weakify(self);
    
    InputUserInfoViewModel* vm = [[InputUserInfoViewModel alloc] initWithParams:@{SUViewModelTitleKey:@"修改简介"}];
    vm.strText = self.viewModel.expertSubmitData.intro;
    vm.type = 1;
    vm.reqType = @"EXPERT_INTRO";
    InputUserInfoViewController* vc = [[InputUserInfoViewController alloc] initWithViewModel:vm];
    
    [[[RACObserve(vm, strText) deliverOnMainThread] filter:^BOOL(id value) {
        return value != nil;
    }] subscribeNext:^(id x)
     {
         NSLog(@"JJ Text is %@", x);
         
         @strongify(self);
         
         self.viewModel.expertSubmitData.intro = x;
     }];
    
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)_push2EditMechanismIntroVC
{
    @weakify(self);
    
    InputUserInfoViewModel* vm = [[InputUserInfoViewModel alloc] initWithParams:@{SUViewModelTitleKey:@"机构简介"}];
    vm.strText = self.viewModel.insutitutionSumitData.intro;
    vm.type = 1;
    vm.reqType = @"MECHANISM_INTRO";
    InputUserInfoViewController* vc = [[InputUserInfoViewController alloc] initWithViewModel:vm];
    
    [[[RACObserve(vm, strText) deliverOnMainThread] filter:^BOOL(id value) {
        return value != nil;
    }] subscribeNext:^(id x)
     {
         NSLog(@"JJ Text is %@", x);

         @strongify(self);

         self.viewModel.insutitutionSumitData.intro = x;
     }];
    
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)_push2EditMechanismServVC
{
    @weakify(self);
    
    UserManagerV2* um = [UserManagerV2 sharedUserManagerV2];
    
    InputUserInfoViewModel* vm = [[InputUserInfoViewModel alloc] initWithParams:@{SUViewModelTitleKey:@"修改机构服务内容"}];
    vm.strText = self.viewModel.insutitutionSumitData.servContent;
    vm.type = 1;
    vm.reqType = @"MECHANISM_SERV";
    InputUserInfoViewController* vc = [[InputUserInfoViewController alloc] initWithViewModel:vm];
    
    [[[RACObserve(vm, strText) deliverOnMainThread] filter:^BOOL(id value) {
        return value != nil;
    }] subscribeNext:^(id x)
     {
         NSLog(@"JJ Text is %@", x);

         @strongify(self);

         self.viewModel.insutitutionSumitData.servContent = x;
     }];
    
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)_push2EditCompanyInfo1VC
{
    @weakify(self);
    
    UserManagerV2* um = [UserManagerV2 sharedUserManagerV2];
    
    InputUserInfoViewModel* vm = [[InputUserInfoViewModel alloc] initWithParams:@{SUViewModelTitleKey:@"修改机构联系方式"}];
    vm.strCompanyName = self.viewModel.insutitutionSumitData.name;
    vm.strCompanyContacter = self.viewModel.insutitutionSumitData.contacts;
    vm.strCompanyMobile = self.viewModel.insutitutionSumitData.mobile;
    vm.strCompanyAddr = self.viewModel.insutitutionSumitData.address;
    vm.type = 2;
    vm.reqType = @"MECHANISM_INFO";
    InputUserInfoViewController* vc = [[InputUserInfoViewController alloc] initWithViewModel:vm];
    
    [[[RACObserve(vm, strCompanyName) deliverOnMainThread] filter:^BOOL(id value) {
        return value != nil;
    }] subscribeNext:^(id x)
     {
         NSLog(@"strCompanyIntro is %@", x);

         @strongify(self);
         self.viewModel.insutitutionSumitData.name = x;
     }];
    
    [[RACObserve(vm, strCompanyContacter) deliverOnMainThread] subscribeNext:^(id x)
     {
         NSLog(@"strCompanyContact is %@", x);

         @strongify(self);
         self.viewModel.insutitutionSumitData.contacts = x;
     }];
    [[[RACObserve(vm, strCompanyMobile) deliverOnMainThread] filter:^BOOL(id value) {
        return value != nil;
    }] subscribeNext:^(id x)
     {
         NSLog(@"strCompanySerContent is %@", x);

         @strongify(self);
         self.viewModel.insutitutionSumitData.mobile = x;
     }];
    [[[RACObserve(vm, strCompanyAddr) deliverOnMainThread] filter:^BOOL(id value) {
        return value != nil;
    }] subscribeNext:^(id x)
     {
         NSLog(@"strCompanySerContent is %@", x);

         @strongify(self);
         self.viewModel.insutitutionSumitData.address = x;
     }];
    
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)_push2EditCompanyIntroVC
{
    @weakify(self);
    
    InputUserInfoViewModel* vm = [[InputUserInfoViewModel alloc] initWithParams:@{SUViewModelTitleKey:@"修改企业简介"}];
    vm.strText = self.viewModel.enterpriseSubmitData.intro;
    vm.type = 1;
    vm.reqType = @"COMPANY_INTRO";
    InputUserInfoViewController* vc = [[InputUserInfoViewController alloc] initWithViewModel:vm];
    
    [[[RACObserve(vm, strText) deliverOnMainThread] filter:^BOOL(id value) {
        return value != nil;
    }] subscribeNext:^(id x)
     {
         NSLog(@"JJ Text is %@", x);
         
         @strongify(self);
         
         self.viewModel.enterpriseSubmitData.intro = x;
     }];
    
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)_push2EditCompanyInfo2VC
{
    @weakify(self);
    
    InputUserInfoViewModel* vm = [[InputUserInfoViewModel alloc] initWithParams:@{SUViewModelTitleKey:@"修改企业信息"}];
    vm.strCompanyName = self.viewModel.enterpriseSubmitData.name;
    vm.strCompanyContacter = self.viewModel.enterpriseSubmitData.contacterName;
    vm.strCompanyMobile = self.viewModel.enterpriseSubmitData.mobile;
    vm.strCompanyAddr = self.viewModel.enterpriseSubmitData.address;
    vm.type = 2;
    vm.reqType = @"COMPANY_INFO";
    InputUserInfoViewController* vc = [[InputUserInfoViewController alloc] initWithViewModel:vm];
    
    [[[RACObserve(vm, strCompanyName) deliverOnMainThread] filter:^BOOL(id value) {
        return value != nil;
    }] subscribeNext:^(id x)
     {
         NSLog(@"strCompanyIntro is %@", x);
         
         @strongify(self);
         
         self.viewModel.enterpriseSubmitData.name = x;
     }];
    [[[RACObserve(vm, strCompanyContacter) deliverOnMainThread] filter:^BOOL(id value) {
        return value != nil;
    }] subscribeNext:^(id x)
     {
         NSLog(@"strCompanyContact is %@", x);
         
         @strongify(self);
         
         self.viewModel.enterpriseSubmitData.contacterName = x;
     }];
    [[[RACObserve(vm, strCompanyMobile) deliverOnMainThread] filter:^BOOL(id value) {
        return value != nil;
    }] subscribeNext:^(id x)
     {
         NSLog(@"strCompanySerContent is %@", x);
         
         @strongify(self);
         
         self.viewModel.enterpriseSubmitData.mobile = x;
     }];
    [[[RACObserve(vm, strCompanyAddr) deliverOnMainThread] filter:^BOOL(id value) {
        return nil;
    }] subscribeNext:^(id x)
     {
         NSLog(@"strCompanySerContent is %@", x);
         
         @strongify(self);
         
         self.viewModel.enterpriseSubmitData.address = x;
     }];
    
    [self.navigationController pushViewController:vc animated:YES];
}

@end
